import fetch from "@/utils/http";
import { queryToString } from "@/utils/utils";
import { AddShop, EditParams, Evaluate, ShopResponse } from "./shop";
/**
 * 获取商品列表
 */
export function getShopList(query: {
  pageNum: number;
  pageSize: number;
  createBy?: string;
}) {
  return fetch<ShopResponse>(
    `/system/commodity/list?${queryToString(query)}`,
    "MANGMENT",
    {
      method: "get"
    }
  );
}
/**
 * 删除
 */
export function delItem(id: number) {
  return fetch(`/system/commodity/${id}`, "MANGMENT", {
    method: "DELETE"
  });
}
/**
 * 添加商品
 */
export function addShop(data: AddShop) {
  return fetch("/system/commodity", "MANGMENT", {
    method: "POST",
    body: JSON.stringify(data)
  });
}
/**
 * 编辑新闻
 */
export function editItem(data: EditParams) {
  return fetch("/system/commodity", "MANGMENT", {
    method: "PUT",
    body: JSON.stringify(data)
  });
}
// 收藏
export function collectItem(data: { commodityId: number }) {
  return fetch("/system/collect", "MANGMENT", {
    method: "POST",
    body: JSON.stringify(data)
  });
}
// 取消收藏
export function cancelItem(id: number) {
  return fetch(`/system/collect/${id}`, "MANGMENT", {
    method: "DELETE"
  });
}
// 查询商品有没有被收藏
export function searchItemCollect(id: number) {
  return fetch<{ data: boolean }>(`/system/collect/${id}`, "MANGMENT", {
    method: "get"
  });
}
// 收藏的商品
export function getCollectShopList(query: {
  pageNum: number;
  pageSize: number;
  createBy?: string;
}) {
  return fetch<ShopResponse>(
    `system/collect/myCollectList?${queryToString(query)}`,
    "MANGMENT",
    {
      method: "get"
    }
  );
}
// 商品评价
export function getEvaluateList(data: { commodityId: number }) {
  return fetch<Evaluate>(
    `/system/evaluate/list?${queryToString(data)}`,
    "MANGMENT",
    {
      method: "get"
    }
  );
}
// 发表评论
export function publish(data: {
  commodityId: number;
  evaluateId?: number;
  content: string;
}) {
  return fetch("/system/evaluate", "MANGMENT", {
    method: "POST",
    body: JSON.stringify(data)
  });
}
// 删除评论
export function delEvaluate(id: number) {
  return fetch(`/system/evaluate/${id}`, "MANGMENT", {
    method: "DELETE"
  });
}
